package com.zhyl.demo.service.impl;

import com.zhyl.demo.controller.UserController;
import com.zhyl.demo.entity.User;
import com.zhyl.demo.mapper.UserMapper;
import com.zhyl.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public User login(String username, String password) {
        User user =  userMapper.login(username,password);

        return user;
    }

    @Override
    public Boolean register(User user) {
        Integer register = userMapper.register(user);
        if (register>0){
            return true;
        }else {
            return false;
        }

    }

    @Override
    public User selectByUsername(String username) {
        User user = userMapper.selectByUsername(username);
        return user;
    }

    @Override
    public ArrayList<User> getAdminUser() {
        return userMapper.getAdminUser();
    }

    @Override
    public Boolean uploadFace(User user) {
        Integer i = userMapper.uploadInfo(user);
        return i >= 0;
    }

    @Override
    public Boolean deleteUser(int userId) {
        Integer i = userMapper.deleteUser(userId);
        return i>=0;
    }

    //生成随机八位数
    public  long getRandomNumber() {
        return UserController.getRandomNumber();
    }

    @Override
    public User getUserInfo(Integer userId) {
        return userMapper.getUserInfo(userId);
    }

    @Override
    public Boolean updateUser(User user) {
        int i =userMapper.updateUser(user);
        return i>=0;
    }
}
